package com.smm.service;

import com.jn.sqlhelper.dialect.pagination.PagingRequest;
import com.jn.sqlhelper.dialect.pagination.PagingRequestContextHolder;
import com.jn.sqlhelper.dialect.pagination.PagingResult;
import com.smm.dao.CollectDao;
import com.smm.entity.Collect;
import com.smm.entity.Song;
import com.smm.entity.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class CollectService {
    @Resource
    private CollectDao collectDao;

    private static Logger log = LoggerFactory.getLogger(CollectService.class);

    public Integer addCollect(Collect collect) {
        return collectDao.addCollect(collect);
    }

    public Integer deleteCollect(Integer id) {
        return collectDao.deleteCollect(id);
    }

    public Collect findColect(Collect collect) {
        return collectDao.findCollect(collect);
    }

    public Integer updateCollect(Collect collect) {
        return collectDao.updateCollect(collect);
    }

    public PagingResult findCommentPage(Collect collect, Integer pageSize, Integer pageNumber) {
        PagingRequest request = new PagingRequest().setPageNo(pageNumber).setPageSize(pageSize);
        PagingRequestContextHolder.getContext().setPagingRequest(request);
        List<Collect> collects = collectDao.findCollectPage(collect);
        log.info("list长度: " + collects.size());
        return request.getResult().setItems(collects);
    }
}
